{include file="public/header" /}
<style>
    .layui-form-label {
        width: 15%;
    }

    .layui-input-inline {
        width: 70% !important;
        margin-left: 2%;
    }

    .diqu ul li {
        float: left;
        margin-left: 10px;
        margin-top: 20px;
    }
</style>

<body>
    <div class="x-body">
        <form action="{:url('savepsot')}" class="layui-form" id="form">
            <input type="hidden" name="id" value="{$info?$info.id:''}" />

            <div class="layui-form-item">
                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">优惠券标题</label>
                    <div class="layui-col-md9"> <input type="text" name="title" lay-verify="required"
                            lay-reqtext="请填写优惠券标题" placeholder="请填写优惠券标题" class="layui-input"
                            value="{$info?$info.title:''}" />
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">优惠券类型</label>
                    {if empty($info)}
                    <input type="radio" name="types" lay-filter="types" value="1" title="普通优惠券">
                    <input type="radio" name="types" lay-filter="types" value="2" title="订单满减优惠券">
                    <input type="radio" name="types" lay-filter="types" value="3" title="积分现金券">
                    {else}
                    <input type="radio" name="types" lay-filter="types" value="1" title="普通优惠券" <?php if($info->types == 1){?>checked
                    <?php }?>>
                    <input type="radio" name="types" lay-filter="types" value="2" title="订单满减优惠券" <?php if($info->types == 2){?>checked
                    <?php }?>>
                    <input type="radio" name="types" lay-filter="types" value="3" title="积分现金券" <?php if($info->types == 3){?>checked
                    <?php }?>>
                    {/if}
                </div>
            </div>

            <div class="layui-form-item" id="product_ids" {if empty($info) || ($info->types!=1)} style=" display: none;"{/if}>
                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">会员等级</label>
                    <div class="layui-col-md9 diqu">
                        <ul>
                            {volist name="Level" id="vo"}
                            {if in_array($vo.id,$levelid) /}
                            <li><input type="checkbox" checked name="level_ids[]" value="{$vo.id}"
                                    title="{$vo.title}"></li>
                            {else/}
                            <li><input type="checkbox" name="level_ids[]" value="{$vo.id}" title="{$vo.title}"></li>
                            {/if}
                            {/volist}
                        </ul>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" id="receive" {if empty($info) || ($info->types!=2)} style=" display: none;"{/if}>
                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">领取次数</label>
                    {if empty($info)}
                    <input type="radio" name="receive" value="1" title="一次" checked>
                    <input type="radio" name="receive" value="2" title="不限次数">
                    {else}
                    <input type="radio" name="receive" value="1" title="一次" <?php if($info->receive == 1){?>checked
                    <?php }?>>
                    <input type="radio" name="receive" value="2" title="不限次数" <?php if($info->receive == 2){?>checked
                    <?php }?>>
                    {/if}
                </div>
                
                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">订单金额</label>
                    <div class="layui-col-md9"> <input type="text" name="term_money" lay-reqtext="请填写订单满多少可领取" placeholder="请填写订单满多少可领取"
                            onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" class="layui-input"
                            value="{$info?$info.term_money:''}" />
                    </div>
                </div>
                
            </div>

            <div class="layui-form-item">
                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">金额</label>
                    <div class="layui-col-md9"> <input type="text" name="money" lay-reqtext="请填写金额" placeholder="请填写金额"
                            onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" class="layui-input"
                            value="{$info?$info.money:'0'}" />
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">优惠金额</label>
                    <div class="layui-col-md9"> <input type="text" name="sale_money" lay-reqtext="请填写优惠金额"
                            placeholder="请填写优惠金额" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"
                            class="layui-input" value="{$info?$info.sale_money:'0'}" />
                    </div>
                </div>
            </div>

            <div class="layui-form-item">

                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">有效期</label>
                    <div class="layui-col-md9">
                        <input type="number" name="time" lay-verify="required" lay-reqtext="请填写有效期" placeholder="请填写有效期"
                            class="layui-input" value="{$info?$info.time:'0'}" />
                    </div>
                </div>
            </div>
            <div class="layui-form-item">

                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">活动有效期</label>
                    <div class="layui-col-md9">
                        <input class="layui-input date" placeholder="活动有效期" name="end_time"
                            value="{$info?$info.end_times:''}" lay-verify="required" style="" autocomplete="off" />

                    </div>
                </div>
            </div>


            <div class="layui-form-item">

                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">优惠数量</label>
                    <div class="layui-col-md9">
                        <input type="number" name="num" lay-verify="required" lay-reqtext="请填写优惠数量"
                            placeholder="请填写优惠数量" class="layui-input" value="{$info?$info.num:''}" />
                    </div>
                </div>
            </div>


            <div class="layui-form-item">

                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">排序</label>
                    <div class="layui-col-md9">
                        <input type="number" name="sort" lay-verify="required" lay-reqtext="请填写排序" placeholder="请填写排序"
                            class="layui-input" value="{$info?$info.sort:'0'}" />
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row">
                    <label class="layui-form-label layui-col-md2">选择商品</label>
                    <div class="layui-col-md9 diqu">
                        <ul>
                            {volist name="list" id="vo"}
                            {if in_array($vo.id,$chekid) /}
                            <li><input type="checkbox" checked name="product_ids[]" value="{$vo.id}"
                                    title="{$vo.title}"></li>
                            {else/}
                            <li><input type="checkbox" name="product_ids[]" value="{$vo.id}" title="{$vo.title}"></li>
                            {/if}
                            {/volist}
                        </ul>
                    </div>
                </div>
            </div>
            <div class="layui-form-item" style="text-align: center;">
                <button class="layui-btn" lay-filter="save" lay-submit formObj="#form">保存</button>
            </div>
        </form>
    </div>
</body>
{include file="public/footer" /}
<script>
    layui.use(['form', 'layer', 'jquery'], function () {
        $ = layui.jquery;
        var layer = layui.layer,
            form = layui.form;
        //监听多选框点击事件  主要是通过 lay-filter="sex"  来监听
        form.on('radio(types)', function (data) {
            console.log(data);　　//打印当前选择的信息
            if (data.value==1) {　　　　　　//判断当前多选框是选中还是取消选中
                $("#receive").hide();
                $("#product_ids").show();
            }else if (data.value==2) {　　　　　　//判断当前多选框是选中还是取消选中
                $("#receive").show();
                $("#product_ids").hide();
            }else {
                $("#receive").hide();
                $("#product_ids").hide();
            }
        });
    })
</script>

</html>